package com.itic.system.order.orderAfterSale.service;

import com.itic.appbase.framework.type.DealState;
import com.itic.system.order.order.persistence.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.system.order.orderAfterSale.persistence.dao.OrderAfterSaleDao;
import com.itic.system.order.orderAfterSale.persistence.model.OrderAfterSale;
import com.itic.system.order.orderAfterSale.persistence.model.OrderAfterSaleExample;


@Service
@Transactional
public class OrderAfterSaleService
     extends CrudService<OrderAfterSaleDao,OrderAfterSale,OrderAfterSaleExample> {
    @Autowired
    private OrderAfterSaleDao orderAfterSaleDao;

    /**
     * 添加售后记录
     * @param userId
     * @param order
     * @param money
     * @param collageId
     * @return
     */
    public String addOrderAfterSale(String userId, Order order ,double money,String collageId){
        OrderAfterSale orderAfterSale = new OrderAfterSale();
        orderAfterSale.setUserId(userId);
        orderAfterSale.setOrderNo(order.getOrderNo());
        orderAfterSale.setMoney(money);
        orderAfterSale.setCollageId(collageId);
        orderAfterSale.setDealState(DealState.Apply.getState());
        return this.add(orderAfterSale);
    }

    /**
     * 根据订单号查询订单售后
     * @param orderNo
     * @return
     */
    public OrderAfterSale getOrderAfterSaleByOrderNo(String orderNo){
        OrderAfterSale orderAfterSale = this.orderAfterSaleDao.getOrderAfterSaleByOrderNo(orderNo);
        return orderAfterSale;
    }

    /**
     * 编辑售后订单状态
     * @param orderAfterSale
     * @param dealState
     * @return
     */
    public String editOrderAfterSaleState(OrderAfterSale orderAfterSale,DealState dealState,String outRefundNo,String reason){
       orderAfterSale.setDealState(dealState.getState());
       orderAfterSale.setDealState(dealState.getState());
       orderAfterSale.setRefundFailReason(reason);
       orderAfterSale.setReturnNo(outRefundNo);
       return this.edit(orderAfterSale);
    }

}